

<?php
/*
 * Script file for Sand Dollar Media
 * ===============================================
 * Date: March 17th, 2012
 * Created By: Integration Team
 * ===============================================
 * Criteria:
 * 1. Only IM Skus 
 * 2. Only skus that have QTY > 0
 * 3. MAP field from IM file needs to go in minimal_price column if MAP is 0, leave blank 
 * 4. Suffix sku field with 'im' or 'td' - e.g. 1234td
 * 5. use custom category tree in custom_category table for categories column 
 * 6. Manufacturer name replacements - refer to cleanup_manufacturers()
 * 7. URL key should only contain alpha-numeric with only - replacing spaces - refer to URL_key()
 *  
 */
set_time_limit(3000);
require_once 'config.php';

$categorytemplate = new categoryClass();
$cda = $categorytemplate->getCategoryDisplayAttributes(4800);
$product = new OmegaProduct(1016410872, $cda, True, true, true,true,true,true,true);

echo $product->get_techspecs()."<br/>";
echo $product->get_product_overview();
exit();

//echo "Memory After Product1:".memory_get_usage(TRUE).Line_Terminator;
//$product2 = new product(1016410872, $cda, True, true, true,true,false,false,false);
//echo "Memory After Product2:".memory_get_usage(TRUE).Line_Terminator;
//$product3 = new product(1016410872, $cda, True, true, true,true,false,true);
//echo "Memory After Product3:".memory_get_usage(TRUE).Line_Terminator;
//echo $product2->get_obj_vars()."<br/>";
$a = array(10001441,10001461,10001751,10001752,10001755,10001756,10001757,10001806,10002086,10002087);

foreach($a as $key=>$value){
    $object_array[$value]=new product($value, $cda, True, true, true,true,true,true,true);
}
$b = $object_array[10002087];
echo $b->get_product_overview();
echo $b->get_techspecs()."<br/>";
echo $b->get_accessoryProducts();
echo $b->get_similarProducts();
echo $b->get_upsellProducts()."<br/>";
echo $b->get_largest_image();
exit();
 
    
echo var_dump($object_array);
echo "Memory After 10 Products:".memory_get_usage(TRUE).Line_Terminator;
exit();
echo $product->get_techspecs();
echo "<br/>";
echo $product->get_keywords();
echo "<br/>";
echo $product->get_description(1);
echo "<br/>";
echo $product->get_product_overview();
echo "<br/>";
echo $product->get_upsellProducts();
echo $product->get_similarProducts();
echo $product->get_accessoryProducts();
//echo var_dump($product->get_upsellProducts());
echo "<br/>";
//echo var_dump($product->get_similarProducts());
exit();
$query = "Select pa.attributeid as attributeId,
          pa.displayvalue as displayValue,
          pi.type as imageType,
          pd.type as descriptionType,
          pd.description as description,
          pk.keywords as keywords
          from ".
         Spex_DB_name.
        ".productattribute pa 
        left join productimages pi
        on pa.productid = pi.productid
        left join productdescriptions pd
        on pa.productid = pd.productid and pd.localeid = 1
        left join productkeywords pk on pa.productid = pk.productid and pk.localeid = 1
        where pa.productid = 10000039 and pa.localeid = 1";


$result = query($query);
$attributearray = array();
$images = array();
$descriptions = array();
$keywords = "";
while($row = mysql_fetch_assoc($result))
{
    $attributearray[$row['attributeId']][] = $row['displayValue'];
    $images[$row['imageType']]=$row['imageType'];
    $descriptions[$row['descriptionType']]=$row['description'];
    $keywords = $row['keywords'];
}

//$product->set_techspecs($attributearray);
$product->set_resources($images);
$product->set_descriptions($descriptions);
$product->set_keywords($keywords);
$product->set_upsellProducts(array('product1'=>array('URL'=>"XXX.com",
                                                    'image'=>"http://content.blah",
                                                    'Desc'=>"This is a desc"),
                                    'product2'=>array('URL'=>"XXX.com",
                                                    'image'=>"http://content.blah",
                                                    'Desc'=>"This is a desc")
                                   )
                            );

echo $product->get_techspecs();
echo $product->get_largest_image();
echo $product->get_description(2)."<br/>";
echo $product->get_keywords();
echo var_dump($product->get_upsellProducts(1));



exit();
$categorytemplate = new categoryClass();
$file = new FileWriter(Output_File_Name,Output_File_Directory,'a',TRUE);
$logfile = new FileWriter('log.txt', Log_File_Directory, 'a', FALSE);
$content = "";
$records = 0;
$timer = new timerClass();
$overalltimer = new timerClass();
$overalltimer->start();
$timer->start();
//Product File

$product_header_array = array('productcode',                    //MFGPARTNO from the dnh_price table - Append -PTX
                                    'productname',              //Type 2 description - should start with Manufacturer Name
                                    'ProductWeight',            //Product Weight
                                    'productcategory',          //Custom product category 
                                    'ProductDescription',       //Type 1 - full description
                                    'freeshippingitem',         //'N' for all items
                                    'productmanufacturer',      //Manufacturer
                                    'ProductNameShort',         //Type 2 description - should start with Manufacturer Name
                                    'Photo_AltText',            //Type 2 Description - should start with Manufacturer Name - Append with "| SDC-Photo
                                    'METATAG_Title',            //Type 2 Description - should start with Manufacturer Name - Append with "| SDC-Photo
                                    'metatag_description',      //Type 2 Description - Start with "Shop for", then Manufacturer Name and Append with "at SuperDigitalCity" 
                                    'METATAG_Keywords',         //Type 2 description - should start with Manufacturer Name
                                    'ProductDescriptionShort',  //Type 1 - full description - Remove any colon 
                                    'ProductFeatures',          //Overview - custom formatted    
                                    'TechSpecs',                //Tech Specs - custom formatted
                                    'ExtInfo',                  //Package contents - custom formatted
                                    'ProductDescription_AbovePricing',//Description Type 2 - starting with Manufacturer Name - Should not exceed 40 characters
                                    'ProductCondition',               //Product Condition attribute - If refurbished or remanufacturered - skip   
                                    'Vendor_PartNo',            //D&H sku number    
                                    'UPC_code');                //UPC

$product_header_string = '"';
$product_header_string .= implode('"'.Delimiter.'"', $product_header_array);
$product_header_string .= "\"".Line_Terminator;



$file->write($product_header_string);

echo "Took ".$timer->getElapsedTime()." seconds to write header".Line_Terminator;
$timer->start();

$result = query("Select distinct dnhprice.dnh_sku as dnhSku,
                dnhprice.mfgpartno as productcode,
                p.categoryid as categoryId,
                p.mfgpartno as mfgpartno,
                p.productid as productId,
                mn.name as manufacturer,
                (Select sku from ".Spex_DB_name.".productskus where localeid = 1 and name = 'UPC' and productid = p.productid limit 1) as upc
                from ".Custom_DB_name.".dnh_price dnhprice
                join ".Spex_DB_name.".productskus ps on dnhprice.dnh_sku = ps.sku and ps.localeid = 1 and ps.name = 'D&H Distributing Co., Inc'
                join ".Spex_DB_name.".product p on ps.productid = p.productid 
                join ".Spex_DB_name.".manufacturer mn on p.manufacturerid = mn.manufacturerid
                where p.manufacturerid in (Select distinct manufacturerid from ".Custom_DB_name.".manufacturer_filter)"
                );

echo "Took ".$timer->getElapsedTime()." seconds to run query".Line_Terminator;
        

while($row = mysql_fetch_assoc($result)){
    
    $timer->start();
    $cda = $categorytemplate->getCategoryDisplayAttributes($row['categoryId']);
    $product = new OmegaProduct($row['productId'],$cda, Locale, Product_Template, TRUE, FALSE);
    echo "Took ".$timer->getElapsedTime()." seconds to get single product info".Line_Terminator;
    
    if($product->get_description(2)=='')
    {
        $logfile->write(date("Y.m.d g:i a").$row['productId']." is missing Description Type 2".Line_Terminator);
        if($product->get_description(1)==''){
            $logfile->write(date("Y.m.d g:i a").$row['productId']." is missing Both Description Type 2 and 1 - Will Skip Product".Line_Terminator);
            $description = "";
        }
        else
        {
            $description = $product->get_attribute(34113319)." ".$product->get_description(1);
        }
        
    }
    else{
        $description = $product->get_description(2);
    }
    
    
    if($description<>'')
        //No point in exporting the product if the required fields are missing 
    {
        $condition = $product->get_attribute(34111115611);
        
        if($condition<>'Refurbished'&&$condition<>'Remanufactured')
            //Products should only be exported if the condition is New
            //This is not an entirely accurate check since only a 
            //very small subset of the products have any information on this attribute
        {
            $manufacturer_and_ProductName = cleanup(str_replace(",", "",$description));
            $long_desc = $product->get_description(3);
            $short_description = $product->get_description(2);
            $description_above_pricing = "";
            if($product->get_attribute(341452)<>'')
            {
                $marketing_info = "<br/>".$product->get_attribute(341452);
            }
            else
            {
                $marketing_info = "";
            }
            if($long_desc<>"")$description_above_pricing.="<br/><span>-".$long_desc."</span>";
            
            if($row['manufacturer']=='PENTAX Imaging Company')
            {
                //Only Pentax products need to have the suffix of -PTX
                $productcode = $row['productcode'].'-PTX';
            }
            else
            {
                $productcode = $row['productcode'];
            }
            
            
            
            
            $content.= '"'.cleanup($productcode).'","'.
                $manufacturer_and_ProductName.'","'.
                cleanup($product->get_attribute(341975)).'","'.
                cleanup($product->get_mapped_category($row['categoryId'])).'","'.
                cleanup($marketing_info).'","'.
                'N","'.
                cleanup(str_replace(",", "",$row['manufacturer'])).'","'.
                $manufacturer_and_ProductName.'","'.
                $manufacturer_and_ProductName.' |SDC-Photo","'.
                $manufacturer_and_ProductName.' |SDC-Photo","'.
                "Shop For ".$manufacturer_and_ProductName.' at SuperDigitalCity","'.
                $manufacturer_and_ProductName.'","'.
                str_replace(":", "",cleanup("<br/>-".$product->get_description(1))).'","'.
                cleanup($product->get_product_overview()).'","'.
                cleanup($product->get_techspecs()).'","'.
                cleanup($product->get_package_contents()).'","'.
                cleanup($description_above_pricing).'","'.
                'New","'.
                cleanup($row['dnhSku']).'","'.
                $row['upc'].'"'.    
                Line_Terminator;
        $records++;
        }
    
    }
    
unset($product); 

    if($records==Record_Buffer)
    {
        $file->write($content);
        $content = "";                
        $records = 0;           
    }

}
if ($content <> "")
{
    $timer->start();
    //Dump remaining records that are left over and didn't reach the record buffer value 
    $file->write($content);                
    $file->close_handle();
    echo "Took ".$timer->getElapsedTime()." seconds to write content".Line_Terminator;
}

echo $overalltimer->getElapsedTime();

?>

</html>